package com.hfi.ood.srp.good;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ChangLiang
 * @date 2020/5/12
 */
public class CourseOffering {

    /**
     * 课程
     */
    private Course course;

    /**
     * 上课位置
     */
    private String location;

    /**
     * 教师
     */
    private String teacher;

    /**
     * 此课的学生容量
     */
    private int maxStudent;

    List<Student> students = new ArrayList<>();

    public Course getCourse() {
        return course;
    }

    public int getMaxStudent() {
        return maxStudent;
    }

    public List<Student> getStudents() {
        return students;
    }

    // 将CourseService的逻辑进行划分 把主要逻辑移动到CourseOffering中
    public void addStudent(Student student){

        if(student.canAttend(course)
                && this.isFull()){
            students.add(student);
        }
    }

    private boolean isFull() {
        return this.maxStudent > students.size();
    }
}
